import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.DatagramSocket;
import java.net.SocketException;
import java.util.HashMap;
import java.util.Map;

import org.json.JSONObject;


public class Client {
	
	private static final int PORT = 5188;
	private static final String IP = "127.0.0.1";

	private MySocketController socketController;
	
	public Client(){
		try {
			socketController = new MySocketController(new DatagramSocket(PORT+1));
		} catch (SocketException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public void communicate(){
		while(true){
			try {
				Map<String, String> info = new HashMap<String, String>();
				info.put("operation", "login");
				info.put("username", "Bird");
				info.put("password", "KillPigs");
				JSONObject request = new JSONObject(info);
				socketController.setContent(request.toString(), 5188, "127.0.0.1");
				while(true){
					System.out.println(socketController.getContent());
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		
	}
	
	public static void main(String[] args) {
		Client m = new Client();
		m.communicate();
	}
}
